package com.github.nuggets.model.result;


import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

/**
 * @description: 统一的返回结果
 * @author: wangsj
 * @date: 2022/3/17 7:00 下午
 */

@Data
@AllArgsConstructor
@NoArgsConstructor
@Accessors(chain = true)
public class BaseResult<T> {

    private Integer code;

    private String message;

    private T data;


    public static <T> BaseResult<T> success(T data, String message) {
        return new BaseResult<>(ResultInfoEnum.SUCCESS.getResultCode(), message, data);
    }

    public static <T> BaseResult<T> success(T data) {
        return success(data, ResultInfoEnum.SUCCESS.getResultMsg());
    }

    public static <T> BaseResult<T> success() {
        return success(null);
    }

    public static <T> BaseResult<T> fail(Integer code,String message) {
        return new BaseResult<>(code, message, null);
    }

    public static <T> BaseResult<T> fail(String message) {
        return new BaseResult<>(ResultInfoEnum.FAIL.getResultCode(), message, null);
    }

    public static <T> BaseResult<T> fail() {
        return fail(ResultInfoEnum.FAIL.getResultMsg());
    }

}
